<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/bootstrap/bootstrap3/css/bootstrap.css">
    <link rel="stylesheet" href="/js/bootstrap/bootstrap3/css/bootstrap-theme.css">

    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap3/js/bootstrap.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-table/bootstrap-table.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>

    <script type="text/javascript" src="/js/bootstrap/bootstrap-bootbox/bootbox.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootStrap-addTabs/bootstrap.addtabs.css">
    <script type="text/javascript" src="/js/bootstrap/bootStrap-addTabs/bootstrap.addtabs.min.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-treeview/bootstrap-treeview.min.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-treeview/bootstrap-treeview.min.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-fileinput/css/fileinput.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-fileinput/js/fileinput.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap-fileinput/js/locales/zh.js"></script>
</head>
<body>
<div id="toolBar">
    <button type="button" class="btn btn-success" onclick="addOrderInfo()">新增</button>
</div>
<div class="table" id="myTable"></div>
</body>
<script type="text/javascript">
    $(function(){
        tbs();
    })

    //表格
    function tbs() {
        $('#myTable').bootstrapTable({
            toolbar:'#toolbar',
            url:'selectAdmin',//获取数据地址
            pagination:true, //是否展示分页
            pageList:[1, 3, 5, 7],//分页组件
            pageNumber:1,//当前页
            pageSize:1,//默认每页条数
            search:true,//是否显示搜索框
            //searchText:'试试',//初始化搜索文字
            showColumns:false,//是否显示 内容列下拉框
            showToggle:false,//是否显示 切换试图（table/card）按钮
            showPaginationSwitch:false,//是否显示 数据条数选择框
            showRefresh:false,//是否显示刷新按钮
            detailView:false,//设置为 true 可以显示详细页面模式。
            showFooter:false,//是否显示列脚
            clickToSelect: true, //是否启用点击选中行
            sidePagination:'client',//分页方式：client客户端分页，server服务端分页（*
            striped:true,//斑马线列表
            /*queryParams:function(){
                var parName=$("#parName").val();
                return {
                    page: this.pageNumber,
                    rows: this.pageSize,
                    'parName':parName
                };
            },*/
            columns:[
                {field:"id",title:"用户Id",width:100},
                {field:"name",title:"用户名",width:100},
                {field:"port",title:"所属端口",width:100},
                {field:"shoudIp",title:"Ip地址",width:100}
            ]
        });
    }
    //查询按钮
    function search(){
        $('#myTable').bootstrapTable('refresh');
    }
    var res;
    function createAddContent(url){
        $.ajax({
            url:url,
            async:false,//同步
            success:function(data){
                res = data;
            }
        });
        return res;
    }
    //新增按钮
    function addOrderInfo(){
        bootbox.dialog({
            title:'添加项目信息',
            message: createAddContent("toAddPost"),//弹出框的内容 能够识别html标签
            closeButton: true,//是否显示关闭按钮
            buttons : {
                "success" : {
                    "label" : "<i class='icon-ok'></i> 保存",
                    "className" : "btn-sm btn-success",
                    "callback" : function() {
                        $.ajax({
                            url:'addCmy',
                            type:'post',
                            data:$("#addOrder").serialize(),
                            //dataType:'json',
                            success:function(data){
                                bootbox.alert({
                                    size: "small",
                                    title: "提示",
                                    message: "新增数据成功"
                                })
                                $('#myTable').bootstrapTable('refresh');
                            }
                        });
                    }
                },
                "cancel" : {
                    "label" : "<i class='icon-info'></i> 取消",
                    "className" : "btn-sm btn-danger",
                    "callback" : function() {

                    }
                }
            }

        });
    }
    //删除/单
    function openDelete(xid) {
        var ids="";
        ids=xid;
        deleteUser(ids);
    }
    //批量删除
    function deleteUserList() {
        //获取所有被选中的记录
        var rows = $("#myTable").bootstrapTable('getSelections');
        if (rows.length== 0) {
            alert( "请先选择要删除的记录!" );
            return ;
        }
        var ids = '' ;
        for ( var i = 0; i < rows.length; i++) {
            ids+= ids==""?rows[i].id:","+rows[i].id;
        }
        // ids = ids.substring(0, ids.length - 1);
        deleteUser(ids);
    }
    //删除
    function deleteUser(ids) {
        var msg = "您真的确定要删除吗？" ;
        if (confirm(msg) == true ) {
            $.ajax({
                url: "<%=path%>/cross/reCrde.do" ,
                type: "get" ,
                data: {
                    ids: ids
                },
                success: function () {
                    alert("删除成功")
                    //重新加载记录
                    //重新加载数据
                    $('#myTable').bootstrapTable('refresh');

                }
            });
        }
    }
    //修改
    function updateinfo(xid){
        $.ajax({
            url:"<%=path%>/cross/selectRe.do",
            type:"get",
            data:{xid:xid},
            success:function(){
            }
        }),
            bootbox.dialog({
                title:'修改信息',
                message: createAddContent("<%=path%>"+"/cross/toAddCross.do"),//弹出框的内容 能够识别html标签
                closeButton: true,
                buttons : {
                    "success" : {
                        "label" : "<i class='icon-ok'></i> 保存",
                        "className" : "btn-sm btn-success",
                        "callback" : function() {
                            $.ajax({
                                url:'<%=path%>/cross/addCmy.do',
                                type:'post',
                                data:$("#addOrder").serialize(),
                                //dataType:'json',
                                success:function(data){
                                    bootbox.alert({
                                        size: "small",
                                        title: "提示",
                                        message: "修改数据成功"
                                    })
                                    $('#myTable').bootstrapTable('refresh');
                                }
                            });
                        }
                    },
                    "cancel" : {
                        "label" : "<i class='icon-info'></i> 取消",
                        "className" : "btn-sm btn-danger",
                        "callback" : function() {

                        }
                    }
                }
            });
    }
</script>
</html>